package com.ideaaedi.zoo.foundation;

import cn.hutool.crypto.GlobalBouncyCastleProvider;
import com.ideaaedi.zoo.foundation.guide.DIYGuidePrinter;
import com.ideaaedi.zoo.foundation.properties.ZooFoundationGuideProperties;
import com.ideaaedi.zoo.foundation.properties.ZooFoundationProperties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * 自动配置
 */
@ImportAutoConfiguration(DIYGuidePrinter.class)
@EnableConfigurationProperties({ZooFoundationGuideProperties.class, ZooFoundationProperties.class})
@ConditionalOnProperty(value = ZooFoundationAutoConfiguration.ENABLE, havingValue = "true", matchIfMissing = true)
public class ZooFoundationAutoConfiguration {
    
    public static final String ENABLE = "zoo.switch.foundation.enable";
    
    @Bean
    @ConditionalOnMissingBean(name = "zooHutoolCryptoConfig")
    @ConditionalOnProperty(value = "zoo.hutool-crypto-config-enable", havingValue = "true", matchIfMissing = true)
    public InitializingBean hutoolCryptoConfig() {
        return () -> {
            // 使用hutool相关加密类加密时，不使用BouncyCastle加密库（而使用jdk自带的加密算法）
            GlobalBouncyCastleProvider.setUseBouncyCastle(false);
        };
    }
}
